package com.sp2.dev.test.mianshi;

import org.junit.Test;

import java.io.File;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by IntelliJ IDEA.
 * User: zhimingli
 * Date: 14-2-14
 * Time: 下午2:41
 * To change this template use File | Settings | File Templates.
 */
public class Precision {
    //double 和float本身确实存在某种缺陷。
    //商业计算要用BigDecimai
    @Test
    public void precision() {
        double d1 = 0.05 + 0.01;//0.060000000000000005
        System.out.println(d1);

        BigDecimal bigDecimal1 = new BigDecimal("0.05");
        BigDecimal bigDeclmal2 = new BigDecimal("0.01");
        BigDecimal sum = bigDecimal1.add(bigDeclmal2);
        System.out.println(sum.toString());
    }

    /**
     * java是值传递还是引用传递？
     */

    //文件测试
    public static void fileTest(String str) {
        String filePath = null;
        if (str == null) {
            filePath = "E:\\学习文件";
        } else {
            filePath = str;

        }
        File file = new File(filePath);
        if (file.isDirectory()) {
            File files[] = file.listFiles();
            for (File otherFile : files) {
                System.out.println("文件名是" + otherFile.getName() + "--是否是文件夹----" + otherFile.isDirectory());
                if (otherFile.isDirectory()) {
                    fileTest(otherFile.getAbsolutePath());
                }
            }
        } else {
            System.out.println("文件名是" + file.getName() + "--是否是文件夹----" + file.isDirectory());
        }
    }

    public static void main(String[] args) {
        fileTest(null);
    }

    @Test
    public void test() {
        Calendar cal = Calendar.getInstance();
        cal.set(2013, 0, 1, 0, 0, 0);//1356969600052
        Long time = cal.getTimeInMillis();
        System.out.println(time);
        System.out.println("------------");
        long oldtime = Long.valueOf(1378893947000L + "");
        SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
        System.out.println(sdf.format(new Date(oldtime)));
    }
}
